package com.example.tests;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.util.logging.Logger;
import org.testng.annotations.AfterMethod;
//import static org.testng.Assert.*;
import org.testng.annotations.Test;

import com.example.fw.GroupDataGenerator;
import com.example.fw.GroupObject;
import com.example.fw.Groups;

public class GroupCreationTests extends TestBase {
	
	//make logger
	private Logger log = Logger.getLogger("GroupCreationTests");
	private int counter;
	
	@Test(dataProvider = "groupsFromFile", dataProviderClass = GroupDataGenerator.class)
	public void testValidGroupCanBeCreated(GroupObject validGroup) throws Exception {
		Groups oldList = app.getGroupHelper().getGroups();
		app.getGroupHelper().createGroup(validGroup);
		Groups newList = app.getGroupHelper().getGroups();
		assertThat(newList, equalTo(oldList.withAdded(validGroup)));
	}
	
	@AfterMethod
	public void testUiAndDbConformsWithModel() {
		if (counter > 10) {
			Groups modelList = app.getHibernateHelper().getGroups();
			Groups dbList = app.getHibernateHelper().getGroups();
			Groups uiList = app.getGroupHelper().getUiGroups();
			assertThat(dbList, equalTo(modelList));
			assertThat(uiList, equalTo(modelList));
			counter = 0;
		} else {
			counter = counter + 1;
		}
		
		// ili sdelat  bez schetchikov proverku ui
		//if (app.getProperty("ui.check")!= null) {
		//Groups modelList = app.getGroupHelper().getGroups();
		//Groups dbList = app.getHibernateHelper().getGroups();
		//Groups uiList = app.getGroupHelper().getUiGroups();
		//assertThat(dbList, equalTo(modelList));
		//assertThat(uiList, equalTo(modelList));
		//} 
		
		//ili sdelat  bez schetchikov proverku ui i db
		//if (app.getProperty("ui.check")!= null) {
		//Groups modelList = app.getGroupHelper().getGroups();
		//Groups uiList = app.getGroupHelper().getUiGroups();
		//assertThat(uiList, equalTo(modelList));
		//} 
		//if (app.getProperty("db.check")!= null) {
		//Groups modelList = app.getGroupHelper().getGroups();
		//Groups dbList = app.getHibernateHelper().getGroups();
		//assertThat(dbList, equalTo(modelList));
		//} 
				

	}	

	
}

